#pragma once

#include <iostream>
#include <string>

#include "read_server_model.hpp"
#include "read_server_view.hpp"

namespace ns_control
{
    using namespace ns_model;
    using namespace ns_view;
    class control
    {
    private:
        model _model;
        view _view;

    public:
        control()
        {
        }
        ~control()
        {
        }

    public:
        bool oneChapter(const std::string &book_id, const std::string &chapter_id, std::string *html)
        {
            chapter chp;
            bool ret = true;
            if (_model.getOneChapter(book_id, chapter_id, &chp))
            {
                LOG(INFO) << "获取小说 " << book_id << " 第 " << chapter_id << " 章节成功!"
                          << "\n";
                _view.oneExpandHtml(chp, html);
            }
            else
            {
                if (!ns_util::fileUtil::readFile("../template_html/unaccess.html", html))
                {
                    LOG(FATAL) << "读取ERRORHTML失败"
                               << "\n";
                }
                ret = false;
            }
            return ret;
        }
    };
}